<?
require 'global.php';

$refer=''; if(isset($_GET["refer"])) {
	$refer=clean($_GET["refer"]);
	setcookie("referer", encrypt($refer));
}

// 已登录状态, 去个人中心
if($customer_id>0) { header('Location:member.html'); exit; }

$gee=$customer;
$url='login';
// 错误集 error array
$errors=array();

$tem_email='';
if(isset($_COOKIE['tem_email'])) $tem_email=$_COOKIE['tem_email']; // 临时账户

$action='you guess';
if(isset($_POST["action"]) && $_POST["action"]!="")$action=clean($_POST["action"]);
if($action=='login'){
	$email='';
	$password='';

	$key='you guess'; // safety key 安全码, 过滤非法提交
	if(isset($_POST["key"]) && $_POST["key"]!="") $key=clean($_POST["key"]);
	if($key != md5('ecomgear'.date('Ymd'))){ exit; } // illegal data. 非法数据, 直接停止执行

	if(isset($_POST["email"]) && $_POST["email"]!="") $email=clean($_POST["email"]);
	if(isset($_POST["password"]) && $_POST["password"]!="") $password=clean($_POST["password"]);

	setcookie('tem_email',$email,time()+3600); // 为客户保存临时账户 save temp account for customer
	$k=$gee->check_sign($email,$password,'email');
	//pre($k);
	if($k==1){
		$tem=$customer->get_row($email,'email');
		$nickname=$tem['nickname'];
		$customer_id=$gee->get_id('email',$email);
		$gee->update_last_login_time($customer_id); // 更新最后登录时间
		setcookie("customer_nickname", encrypt($nickname), time()+3600*24*1);
		setcookie("customer_id", encrypt($gee->get_id('email',$email)), time()+3600*24*1);
		// 跳转url, url to go
		$tem_url='member.html';
		
		if($referer!='') {
			$tem_url=encrypt($referer,'decode').'.php';
			setcookie("referer", '', time()-100);
		}
		$errors[]=array('message'=>WEB_LOGIN_SUCCESSFULLY,'type'=>'message','url'=>$tem_url);
	}
	elseif($k==8) $errors[]=array('message'=>WEB_ACCOUNT_NOT_EXIST,'type'=>'alert','url'=>'login.html');
	elseif($k==4) $errors[]=array('message'=>WEB_ACCOUNT_BANNED,'type'=>'alert','url'=>'login.html');
	else $errors[]=array('message'=>WEB_PASSWORD_WRONG,'type'=>'alert','url'=>'login.html');
}

// SEO setting SEO设置
$title=WEB_LOGIN.' - '.$config['SITE_TITLE_'.LANG];
$dpn=$kwd=$title;

// view 加载视图
require VIEW.$url.'.php';

// end of file
